//package com.fingard.dsp.bank.directbank.boc02;
//
//import com.fingard.dsp.bank.directbank.PaymentState;
//import com.fingard.dsp.bank.directbank.bankInterface.IBatPayRec;
//import com.fingard.dsp.bank.directbank.boc02.utils.AES;
//import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqBatPayRec;
//import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqQryBatPayRec;
//import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsBatPayRec;
//import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsQryBatPayRec;
//import com.fingard.dsp.bank.reqrespobj.batpayrec.detail.RetAtsBatPayRecDetail;
//import com.fingard.dsp.basicbankdata.ebank.EBankData;
//import com.fingard.net.ConnState;
//import com.fingard.text.StringHelper;
//import com.fingard.xml.XElement;
//import com.fingard.xml.XmlTextReader;
//import com.fingard.xml.XmlTextWriter;
//
//
//public class BOC02BatPayRec extends BOC02Base implements IBatPayRec {
//
//
//    //1988
//    @Override
//    public RetAtsBatPayRec d_1988_BatPay(ReqBatPayRec p_req1988) throws Exception {
//        return d_BatPayRec(p_req1988);
//    }
//
//    //批量代付提交
//    public RetAtsBatPayRec d_BatPayRec(ReqBatPayRec p_reqBat) throws Exception {
//        //返回ATS的对象
//        RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_reqBat.reqHeader);
//        try {
//            BOC02Header bankHeader = new BOC02Header();
//            bankHeader.trnid = p_reqBat.reqBatchNO;
//            if ("1988".equals(p_reqBat.reqHeader.transType)) {
//                bankHeader.trncod = "EPAY.REMIT010.01";//交易代码
//            }
//            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
//            writeCommonHeader(xmlWriter, bankHeader);
//            xmlWriter.writeStartElement("request");
//            xmlWriter.writeElementString("acctNbr", p_reqBat.ownAct);
//            xmlWriter.writeElementString("usage", getBankConfig().getMapValueByKey("useType" + p_reqBat.reqHeader.transType, p_reqBat.useType));
//            XElement tmpXElement;
//            StringBuilder stringBuilder = new StringBuilder();
//            while (p_reqBat.readRecord()) {
//                tmpXElement = new XElement("rmtInf", "");
//                tmpXElement.addChild(new XElement("prNm", p_reqBat.ownActName));
//                tmpXElement.addChild(new XElement("pymtAcct", p_reqBat.ownAct));
//                tmpXElement.addChild(new XElement("peAcctNm", AES.encryptToBase64(p_reqBat.readedDetail.recName, bankFront.keyID)));
//                tmpXElement.addChild(new XElement("peAcctNbr", AES.encryptToBase64(p_reqBat.readedDetail.recAct, bankFront.keyID)));
//                String recBankLocation = "";
//                String rcvBnkNbr = "";
//                if (!StringHelper.isNullOrEmpty(p_reqBat.readedDetail.recBankLocation)) {
//                    recBankLocation = p_reqBat.readedDetail.recBankLocation;
//                } else {
//                    String[] ebankCodeName = EBankData.mappingEBankCode(p_reqBat.readedDetail.recBankCode, p_reqBat.readedDetail.recStandardArea);
//                    if (ebankCodeName != null && ebankCodeName[0].length() > 0) {
//                        rcvBnkNbr = ebankCodeName[0];//收款行行号
//                        recBankLocation = ebankCodeName[1];//收款行
//                    }
//                }
//                if (!StringHelper.isNullOrEmpty(recBankLocation)) {
//                    tmpXElement.addChild(new XElement("rcvBnkNm", AES.encryptToBase64(recBankLocation, bankFront.keyID)));
//                } else {
//                    tmpXElement.addChild(new XElement("rcvBnkNm", ""));
//                }
//                tmpXElement.addChild(new XElement("rcvBnkNbr", rcvBnkNbr));
//                tmpXElement.addChild(new XElement("txAmt", AES.encryptToBase64(p_reqBat.readedDetail.payAmount, bankFront.keyID)));
//                tmpXElement.addChild(new XElement("remark", AES.encryptToBase64(p_reqBat.readedDetail.memo, bankFront.keyID)));
//                tmpXElement.addChild(new XElement("reqSeqNbr", p_reqBat.readedDetail.askNumber));
//                tmpXElement.addChild(new XElement("idTp", ""));
//                tmpXElement.addChild(new XElement("idNo", ""));
//                xmlWriter.writeXElement(tmpXElement);
//                stringBuilder.append("prNm=").append(p_reqBat.ownActName).append(",");
//                stringBuilder.append("pymtAcct=").append(p_reqBat.ownAct).append(",");
//                stringBuilder.append("peAcctNm=").append(p_reqBat.readedDetail.recName).append(",");
//                stringBuilder.append("peAcctNbr=").append(p_reqBat.readedDetail.recAct).append(",");
//                stringBuilder.append("rcvBnkNm=").append(recBankLocation).append(",");
//                stringBuilder.append("rcvBnkNbr=").append(rcvBnkNbr).append(",");
//                stringBuilder.append("txAmt=").append(p_reqBat.readedDetail.payAmount).append(",");
//                stringBuilder.append("remark=").append(p_reqBat.readedDetail.memo).append(",");
//                stringBuilder.append("reqSeqNbr=" + "").append(p_reqBat.readedDetail.askNumber).append(",");
//                stringBuilder.append("idTp=" + "").append(",");
//                stringBuilder.append("idNo=" + "").append(",");
//                stringBuilder.append("\r\n");
//            }
//            xmlWriter.writeEndDocument();//写入报文完成
//
//            String signature = signData(getContentBetweenTag(xmlWriter.toXmlString(), "body"));
//            xmlWriter.insertIntoTag("signature", signature);
//            WriteBankLogStep2(stringBuilder);
//            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());//发送银行
//            if (tmpStrRet[0].length() == 0) {
//                StringBuilder tmpSbMsg = new StringBuilder();
//                //解析银行返回
//                System.out.println("3.1.retAts.respCode" + tmpStrRet[1]);
//                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
//                if (tmpBkReader != null) {
//                    String retCd = tmpBkReader.getFirstText("/transaction/header/status/retCd");
//                    String desc = tmpBkReader.getFirstText("/transaction/header/status/desc");
//                    //String location = tmpBkReader.getFirstText("/transaction/header/status/location");
//                    //String appCd = tmpBkReader.getFirstText("/transaction/header/status/appCd");
//                    //String ip = tmpBkReader.getFirstText("/transaction/header/status/ip");
//                    if (isActiveRetCode(retCd)) {
//                        retAts.respCode = "0";
//                        retAts.transState = retCd;
//                        retAts.payInfoCode = retCd;
//                        retAts.respInfo = retCd + "+" + desc;
//                        retAts.reqSeqID = p_reqBat.reqBatchNO;
//                    } else {
//                        retAts.respCode = "0";
//                        retAts.transState = "111+111";
//                        retAts.payInfoCode = "111+111";
//                        retAts.respInfo = retCd + "+" + desc;
//                        retAts.reqSeqID = p_reqBat.reqBatchNO;
//                    }
//                } else {
//                    retAts.respCode = "-1";
//                    retAts.respInfo = tmpSbMsg.toString();
//                }
//            } else if (tmpStrRet[0].equals(ConnState.FAIL)) {
//                retAts.respCode = "0";
//                retAts.respInfo = tmpStrRet[1];
//                retAts.reqSeqID = p_reqBat.reqBatchNO;
//                retAts.transState = PaymentState.FAIL_Batch;
//                retAts.payInfoCode = tmpStrRet[0];
//            } else {
//                retAts.respCode = "-1";
//                retAts.respInfo = tmpStrRet[1];
//            }
//        } catch (Exception e) {
//            retAts.respCode = "-1";
//            retAts.respInfo = e.toString();
//            e.printStackTrace();
//        }
//        if ("-1".equals(retAts.respCode) && StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
//            retAts.reqSeqID = p_reqBat.reqBatchNO;
//        }
//        retAts.writeRetToATS();
//        return retAts;
//    }
//
//    //1998 状态查询
//    @Override
//    public RetAtsQryBatPayRec d_1998_QryBatPay(ReqQryBatPayRec p_reqQryBat) throws Exception {
//        //返回ATS的对象
//        RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_reqQryBat.reqHeader);
//        retAts.respCode = "";
//
//        try {
//
//            BOC02Header bankHeader = new BOC02Header();
//            bankHeader.trncod = "EPAY.QUERY010.01";
//            bankHeader.trnid = getQryTransID();
//            XmlTextWriter xmlWriter = new XmlTextWriter();
//            writeCommonHeader(xmlWriter, bankHeader);
//            xmlWriter.writeStartElement("request");
//            xmlWriter.writeElementString("batchNo", "");
//            xmlWriter.writeElementString("custSeq", p_reqQryBat.reqBatchNO);
//
//            xmlWriter.writeEndDocument();
//            String signature = signData(getContentBetweenTag(xmlWriter.toXmlString(), "body"));
//            xmlWriter.insertIntoTag("signature", signature);
//            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
//            if (tmpStrRet[0].length() == 0) {
//                StringBuilder tmpSbMsg = new StringBuilder();
//                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
//                if (tmpBkReader != null) {
//                    String retCd = tmpBkReader.getFirstText("/transaction/header/status/retCd");
//                    String desc = tmpBkReader.getFirstText("/transaction/header/status/desc");
//                    if (isActiveRetCode(retCd)) {
//                        String batchSt = tmpBkReader.getFirstText("/transaction/body/response/batchSt");
//                        String batchMsg = tmpBkReader.getFirstText("/transaction/body/response/batchMsg");
//                        retAts.respCode = "0";
//                        retAts.payInfoCode = batchSt;
//                        retAts.reqSeqID = p_reqQryBat.reqBatchNO;
//                        retAts.transState = batchSt;
//                        if ("00".equals(batchSt)) {
//                            retAts.respInfo = batchSt + "+处理完成";
//                            while (tmpBkReader.read("/transaction/body/response/rmtRst")) {
//                                RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
//                                tmpRetDetail.result = batchSt + "+" + tmpBkReader.readedXElement.getSingleText("status");
//                                tmpRetDetail.payInfoCode = batchSt + "+" + tmpBkReader.readedXElement.getSingleText("status");
//                                tmpRetDetail.memo = tmpBkReader.readedXElement.getSingleText("epaySeqNbr") + "+"
//                                        + tmpBkReader.readedXElement.getSingleText("msg");
//                                tmpRetDetail.postScript = tmpBkReader.readedXElement.getSingleText("reqSeqNbr");
//                                tmpRetDetail.payAct = p_reqQryBat.ownAct;
//                                retAts.writeRetDetail(tmpRetDetail);
//                            }
//                        } else if ("01".equals(batchSt)) {
//                            retAts.respInfo = batchSt + "+已受理";
//                        } else if ("12".equals(batchSt)) {
//                            retAts.respInfo = batchSt + "+处理中";
//                        } else if ("91".equals(batchSt)) {
//                            retAts.respInfo = batchSt + "+银行拒绝";
//                        }
//                        if (!StringHelper.isNullOrEmpty(batchMsg)) {
//                            retAts.respInfo = retAts.respInfo.concat(",").concat(batchMsg);
//                        }
//                    } else {
//                        retAts.respCode = "0";
//                        retAts.payInfoCode = "111+111";
//                        retAts.reqSeqID = p_reqQryBat.reqBatchNO;
//                        retAts.transState = "111+111";
//                        retAts.respInfo = retCd + "+" + desc;
//                    }
//                } else {
//                    retAts.respCode = "-1";
//                    retAts.respInfo = tmpSbMsg.toString();
//                }
//            } else {
//                retAts.respCode = "-1";
//                retAts.respInfo = tmpStrRet[1];
//            }
//
//        } catch (Exception e) {
//            retAts.respCode = "-1";
//            retAts.respInfo = e.getMessage();
//            e.printStackTrace();
//        }
//        if ("-1".equals(retAts.respCode) && StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
//            retAts.reqSeqID = p_reqQryBat.reqBatchNO;
//        }
//        if ("-1".equals(retAts.respCode)) {
//            retAts.writeBeforeDetail();
//        }
//        retAts.writeAfterDetail();
//        return retAts;
//    }
//
//
//    //9188
//    @Override
//    public RetAtsBatPayRec d_9188_BatPay(ReqBatPayRec p_req9188) throws Exception {
//        throw new Exception("未实现该接口");
//    }
//
//    //9198
//    @Override
//    public RetAtsQryBatPayRec d_9198_QryBatPay(ReqQryBatPayRec p_reqQryBat) throws Exception {
//        throw new Exception("未实现该接口");
//    }
//}
